home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
MacWorld 1997 September
/
Macworld (1997-09).dmg
/
Serious Software
/
Cherwell Scientific Demos
/
pro Fit
/
pro Fit 5.0 demo (fpu).sea
/
pro Fit 5.0 demo (fpu)
/
Examples
/
Programming - intro
/
ChiSquared
next >
Wrap
Text File
|
1996-03-30
|
1KB
|
40 lines
{ A simple example program for calculating the sum of the squared differences }
{ of two columns in a data window. It shows how to use the Input command }
{ to bring up pop-up menus and checkboxes. }
{ To use the program, choose "Add to Menu" from the Misc menu to compile it }
{ Then open a data window (if none is open). Then run the program by choosing "Chi_squared" }
{ from the misc menu. }
program Chi_squared;
var i, count:integer; { our global variables }
num:extended;
y1c,y2c:integer;
norm:boolean;
procedure initialize;
{ this procedure is called once, when the program is compiled. Use it for setting default values }
begin
y1c:=1;y2c:=2;norm:=0;
end;
begin
Input('$Cy1 Column',y1c,'$Cy2 Column',y2c,'$XDivide result by number of points',norm);
{ $C tells Input to show a popup with all columns, $X a checkbox }
num := 0;
count := 0;
for i:=1 to NrRows do
begin
if DataOK(i,y1c) and DataOK(i,y2c) then { if data in both columns }
begin
num := num+sqr(data[i,y1c] - data[i,y2c]);
count := count+1;
end;
end;
if norm then begin
writeln('#points = ',count);
writeln('Chi-squared divided by #points = ',num/count)
end else
writeln('Chi-squared = ',num)
end;